package com.example.analysis.service.impl;

import com.example.analysis.entity.Election;
import com.example.analysis.mapper.ElectionDao;
import com.example.analysis.service.ElectionService;
import com.example.analysis.utils.Response;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ElectionServiceImpl implements ElectionService {
    @Resource
    private ElectionDao electionDao;

    @Override
    public Response<Election> insert(Election aElectionList) {
        try {
            electionDao.insert(aElectionList);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Election> getById(String subId,String studentId) {
        Election aElectionList = electionDao.selectByPrimaryKey(subId,studentId);
        if (aElectionList != null) {
            return new Response<>(true, "Success", aElectionList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<Election> getByName(String ElectionListName) {
        Election aElectionList = electionDao.selectByName(ElectionListName);
        if (aElectionList != null) {
            return new Response<>(true, "Success", aElectionList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
